readyFunc = function(){
    return {
        init: function(){
        	new MenuButton(8, '#menuDiv');
        	initGrid();
    	}
    };
}();

jQuery(readyFunc.init);

function initGrid() {
	$('#datagrid').datagrid({
		url:__MANAGER+'roleQuery_main.do',
		idField: 'userId',
		columns:[[
		    {field:'checked',checkbox:true},
			{field:'roleId',title:'序号',width:100}, 
			{field:'roleName',title:'姓名',width:100}
		]],
		pagination: true,
	    pagePosition: 'bottom',
	    pagination: S4J.utils.pagination()
	}); 
}

function query(tb) {
}

function append(tb) {
}

function edit(tb) {
	var row = $('#datagrid').datagrid('getSelected');
	if(row == null) {
		S4J.utils.showMessage('请选择一条记录');
		return;
	}
	var rows = $('#datagrid').datagrid('getSelections');
	if(rows.lengt > 1) {
		if(row == null) {
			S4J.utils.showMessage('只能选择一条记录');
			return;
		}
	}
	var params = {
			'user.userId': row.userId
	};
	win = S4J.utils.openWindow('修改用户','systemmgr_usermgr_edit',params);
}

function remove(tb) {
	var rows = $('#datagrid').datagrid('getSelections');
	if(rows.lengt == 0) {
		if(row == null) {
			S4J.utils.showMessage('请选择要删除的记录');
			return;
		}
	}
	var ids = '';
	for(var i=0; i<rows.length; i++) {
		if(i == 0) {
			ids = rows[i].userId;
		} else {
			ids += ',' + rows[i].userId;
		}
	}
	var url = __MANAGER+'user_remove.do';
	$.getJSON(url, {userIds: ids}, function(data) {
		S4J.utils.showMessage('操作成功');
		$('#datagrid').datagrid('reload');
		$('#datagrid').datagrid('uncheckAll');
	});
}

function closeWin() {
	$(win).window('destroy');
}